<template>
  <div id="Zhtjsqxm">
    <Breadcrumb content="综合查询(申请项目)" />
    <div class="bodyContent">
      <div class="tools">
        <el-row>
          <el-col :span="24" class="buttonGroup">
            <el-button type="primary" plainv @click="handleSearch">查询</el-button>
            <el-button type="primary" plain @click="htmlToExcel('#printTest', '表格')">导出表格</el-button>
          </el-col>
        </el-row>
      </div>
      <div class="bottomBox">
        <splitpanes class="area">
          <!-- 查询条件 -->
          <pane size="20">
            <splitpanes horizontal @resize="paneChange">
              <pane :size="hTopSize">
                <el-scrollbar style="height: 100%">
                  <div :style="{ height: 'calc((100vh - 120px - 65px) * ' + hTopSize / 100 + ')' }" style="padding: 5px 10px">
                    <vxe-form :data="form" title-width="80px" span="24">
                      <vxe-form-item title="标本日期[起]" class-name="width-100-percentage">
                        <template #default="{ data }">
                          <!-- <vxe-input v-enterNextInput v-model="data.sampledaBegin" type="datetime" placeholder="标本日期[起]" transfer :value-format="'yyyy-MM-dd'" :label-format="'yyyy-MM-dd'" class-name="width-100-percentage" /> -->
                          <el-date-picker v-model="data.sampledaBegin" :value-format="'YYYY-MM-DD HH:mm:ss'" type="datetime" placeholder="标本日期[起]" :shortcuts="shortcuts" style="width: 100%" />
                        </template>
                      </vxe-form-item>
                      <vxe-form-item title="标本日期[止]" class-name="width-100-percentage">
                        <template #default="{ data }">
                          <!-- <vxe-input v-enterNextInput v-model="data.sampledaEnd" type="datetime" placeholder="标本日期[止]" transfer :value-format="'yyyy-MM-dd'" :label-format="'yyyy-MM-dd'" class-name="width-100-percentage" /> -->
                          <el-date-picker v-model="data.sampledaEnd" :value-format="'YYYY-MM-DD HH:mm:ss'" type="datetime" placeholder="标本日期[止]" :shortcuts="shortcuts" style="width: 100%" />
                        </template>
                      </vxe-form-item>
                      <vxe-form-item title="组织机构" class-name="width-100-percentage">
                        <template #default="{ data }">
                          <VxePulldownMultiSelection childIndex="organizationUnit" url="/api/sys/findOrganizationList" :dataObj="{ orgId: store.userInfo.orgId }" @confirmClick="(data) => confirmList(data, 'organizationUnit')" :tableColumn="[
                            { field: 'name', title: '名称' },
                            { field: 'code', title: '编号' }
                          ]" :displayTexts="['name']" :displayTextObj="data.organizationUnitName" :dicValues="data.organizationUnits" includeVal="id" />
                        </template>
                      </vxe-form-item>
                      <vxe-form-item title="院区" class-name="width-100-percentage">
                        <template #default="{ data }">
                          <VxePulldownMultiSelection childIndex="campusArea" :url="'/api/sys/campusArea/findCampusAreaList'" @confirmClick="(data) => confirmCampusAreaList(data)" :tableColumn="[
                              { field: 'campusName', title: '名称' },
                              { field: 'campusCode', title: '编号' }
                            ]" :displayTexts="['campusName']" :displayTextObj="data.campusAreaName" :dicValues="data.campusAreas" includeVal="campusCode" />
                        </template>
                      </vxe-form-item>
                      <vxe-form-item title="报告单元" class-name="width-100-percentage">
                        <template #default="{ data }">
                          <VxePulldownMultiSelection ref="rptGroupRef" childIndex="rptGroup" :url="'/api/rptGroup/findRptGroupByCampusArea'" :dataObj="{ campusAreas: form.campusAreas }" @confirmClick="(data) => confirmCodeList(data, 'rptGroup')" :tableColumn="[
                            { field: 'rptGroupName', title: '名称' },
                            { field: 'rptGroup', title: '编号' }
                          ]" :displayTexts="['rptGroupName']" :displayTextObj="data.rptGroupName" :dicValues="data.rptGroups" includeVal="rptGroup" />
                        </template>
                      </vxe-form-item>

                      <vxe-form-item title="标本号">
                        <template #default="{ data }">
                          <vxe-input ref="wLCodeSInput" type="text" v-model="data.wLCode" @keyup.native.enter="handleSearch" clearable></vxe-input>
                          <!-- <el-input ref="wLCodeEInput" type="text" v-model="data.wLCodeE" placeholder="标本号[止]" @keyup.native.enter="handleSearch" clearable></el-input> -->
                        </template>
                      </vxe-form-item>

                      <!-- 搜索禁用 因为接口返回数据不全 -->
                      <vxe-form-item title="病人类型" class-name="width-100-percentage">
                        <template #default="{ data }">
                          <VxePulldownMultiSelection childIndex="visitType" url="/api/sys/basDictDetail/findDictDetailList" :dataObj="{ code: 'PATTYPE' }" @confirmClick="(data) => confirmList(data, 'visitType')" :tableColumn="[
                            { field: 'name', title: '名称' },
                            { field: 'code', title: '编号' }
                          ]" :displayTexts="['name']" :displayTextObj="data.visitTypeName" :dicValues="data.visitTypes" includeVal="commonId" :searchDisabled="false" />
                        </template>
                      </vxe-form-item>
                      <vxe-form-item title="科室" class-name="width-100-percentage">
                        <template #default="{ data }">
                          <VxePulldownMultiSelection childIndex="dep" url="/api/sys/findDepartmentList" :dataObj="{ orgId: store.userInfo.orgId }" @confirmClick="(data) => confirmList(data, 'dep')" :tableColumn="[
                            { field: 'code', title: '编号' },
                            { field: 'name', title: '名称' }
                          ]" :displayTexts="['name']" :displayTextObj="data.depName" :dicValues="data.deps" includeVal="id" />
                        </template>
                      </vxe-form-item>
                      <vxe-form-item title="申请项目" class-name="width-100-percentage">
                        <template #default="{ data }">
                          <VxePulldownMultiSelection childIndex="fee" url="/lis/fee/item/findFeeItemList" @confirmClick="(data) => confirmList(data, 'fee')" :tableColumn="[
                            { field: 'feeCode', title: '编号' },
                            { field: 'feeName', title: '名称' }
                          ]" :displayTexts="['feeName']" :displayTextObj="data.feeName" :dicValues="data.fees" includeVal="id" />
                        </template>
                      </vxe-form-item>
                      <vxe-form-item title="是否急诊" field="IsUrgent" class-name="width-100-percentage" :item-render="{}">
                        <template #default="{ data }">
                          <vxe-select v-model="data.isUrgent" placeholder="是否急诊" clearable class-name="width-100-percentage">
                            <vxe-option v-for="(item, index) in [
                              {
                                value: 1,
                                label: '是'
                              },
                              {
                                value: 0,
                                label: '否'
                              }
                            ]" :key="index" :label="item.label" :value="item.value"></vxe-option>
                          </vxe-select>
                        </template>
                      </vxe-form-item>
                      <vxe-form-item field="reqDoctorName" title="申请医师">
                        <template #default="{ data }">
                          <VxePulldownMultiSelection childIndex="applicant" :url="'api/user/getUserInfoList?skipCount=0&maxResultCount=200'" @confirmClick="(data) => confirmList(data, 'applicant')" :tableColumn="[
                            { field: 'username', title: '编号' },
                            { field: 'realname', title: '名称' }
                          ]" :displayTexts="['realname']" :displayTextObj="data.applicantName" :dicValues="data.applicants" includeVal="id" />
                        </template>
                      </vxe-form-item>

                      <vxe-form-item field="registrantName" title="检验医师">
                        <template #default="{ data }">
                          <VxePulldownMultiSelection childIndex="registrant" :url="'api/user/getUserInfoList?skipCount=0&maxResultCount=200'" @confirmClick="(data) => confirmList(data, 'registrant')" :tableColumn="[
                            { field: 'username', title: '编号' },
                            { field: 'realname', title: '名称' }
                          ]" :displayTexts="['realname']" :displayTextObj="data.registrantName" :dicValues="data.registrants" includeVal="id" />
                        </template>
                      </vxe-form-item>
                      <vxe-form-item field="reviewerName" title="审核医师">
                        <template #default="{ data }">
                          <!-- <SelectDataList
                        ref="employeeSelectRef"
                        :url="'api/user/getUserInfoList?skipCount=0&maxResultCount=200'"
                        :placeholder="请选择审核医师"
                        :displayField="[
                          { title: '编号', props: 'realname' }, //列标题
                          { title: '名称', props: 'username' }
                        ]"
                        :searchParam="{}"
                        :inputKeyName="'seachValue'"
                        :isPage="false"
                        :title="'点击选择员工'"
                        @selectDataRow="SelectRowClick2"
                        @clearValue="clearValueHandler2"
                        v-model="form.chkDoctorName"
                      /> -->
                          <VxePulldownMultiSelection childIndex="reviewer" :url="'api/user/getUserInfoList?skipCount=0&maxResultCount=200'" @confirmClick="(data) => confirmList(data, 'reviewer')" :tableColumn="[
                            { field: 'username', title: '编号' },
                            { field: 'realname', title: '名称' }
                          ]" :displayTexts="['realname']" :displayTextObj="data.reviewerName" :dicValues="data.reviewers" includeVal="id" />
                        </template>
                      </vxe-form-item>
                    </vxe-form>
                  </div>
                </el-scrollbar>
              </pane>
              <pane :size="100 - hTopSize">
                <vxe-toolbar perfect>
                  <template #buttons>
                    <span class="text-bold margin-left-sm">统计项目</span>
                  </template>
                </vxe-toolbar>
                <div style="height: calc(100% - 25px)">
                  <vxe-table ref="selectOptTable" class="sortable-row-demo mytable-scrollbar" border height="auto" :data="selectOpts" :row-config="{ isCurrent: true, isHover: true, useKey: true }" :keyboard-config="{
                      isArrow: true,
                      isTab: true,
                      isEdit: true
                    }" :show-header="false" resizable show-overflow>
                    <vxe-column type="checkbox" width="26"></vxe-column>
                    <vxe-column type="seq" width="40"></vxe-column>
                    <vxe-column field="name" title="名称" min-width="80"></vxe-column>
                  </vxe-table>
                </div>
              </pane>
            </splitpanes>
          </pane>
          <pane size="80">
            <div style="height: 100%; overflow-y: auto">
              <vxe-table id="printTest" ref="wlAnsGeneralStatisticTable" :data="tableList" :loading="Wloading" height="auto" footer-cell-class-name="table-footer" show-footer border resizable show-overflow class="mytable-scrollbar">
                <vxe-column type="seq" width="40" title="序号"></vxe-column>
                <vxe-column :field="item.field" :title="item.name" :params="{ isValue: item.req }" v-for="(item, index) in tableHeaders" :key="index"></vxe-column>
              </vxe-table>
            </div>
          </pane>
        </splitpanes>
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import Breadcrumb from '@/components/Breadcrumb.vue';
import { reactive, ref, getCurrentInstance, onMounted, watch } from 'vue';
import { IsEmpty, formatDateTime, pageSizes } from '@/utils/common';
import { Splitpanes, Pane } from 'splitpanes';
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage';
import Sortable from 'sortablejs';
import { AppStore } from '../../../stores/store';
import SelectWorkGroup from '../lab_bus/components/SelectWorkGroup.vue'; //报告单元引入下拉组件
import VxePulldownSelection from '@/components/VxePulldownSelection.vue';
import SelectDataList from '@/components/SelectDataList.vue';
import VxePulldownMultiSelection from '@/components/VxePulldownMultiSelection.vue';

let store = AppStore();

let selectWorkGroupRef = ref(null);
let { proxy }: any = getCurrentInstance();
let userInfo = store.userInfo;
let Floading = ref(false);
let Wloading = ref(false);
let Tloading = ref(false);
let wLResults = reactive([]); //标本列表
let traceRecList = reactive([]); //跟踪记录
let operationList = reactive([]); //操作记录
let specResult = ref({}); //标本检测结果
let tableHeaders = reactive([]); //表头
let tableList = reactive([]);
let deptOptions: any = reactive([]); //选择框
let OrganizationList: any = reactive([]); //选择框
let patTypeList: any = reactive([]); //字典表：病人类型
let chkStatusList: any = reactive([]); //字典表：审核状态
let activities = [
  {
    content: '活动按期开始',
    timestamp: '2018-04-15'
  },
  {
    content: '通过审核',
    timestamp: '2018-04-13'
  },
  {
    content: '创建成功',
    timestamp: '2018-04-11'
  }
];
let hTopSize = 40;
let Resultloading = ref(false);
let wLColumnsSelect = [];
let wLColumnsFixed = [
  { key: 'specRc', name: '标本人次', align: 'right' },
  { key: 'xc', name: '项次', align: 'right' },
  { key: 'totalPrice', name: '金额', align: 'right' }
];
let wLColumns = [];
let patTypeCodes = reactive([]); //病人类型所需code集合
let reqDeptCodes = reactive([]); //科室所需code集合
let itemNosCodes = reactive([]); //申请项目所需feeCode集合
let testDoctorCodes = reactive([]); //检验医师所需username集合
let chkDoctorCodes = reactive([]); //审核医师所需username集合

let form = reactive({
  sampledaBegin: formatDateTime(new Date().setTime(new Date().getTime() - 3600 * 1000 * 24 * 7), 'yyyy-MM-dd 00:00:00'),
  sampledaEnd: formatDateTime(new Date(), 'yyyy-MM-dd 23:59:59'),
  orgIds: [],
  organizationUnits: [], //组织机构
  organizationUnitIds: [],
  organizationUnitName: '',
  campusAreas: [], //院区
  campusAreaIds: [],
  campusAreaName: '',
  rptGroups: [], //报告单元
  rptGroupIds: [],
  rptGroupName: '',
  visitTypes: [], //病人类型
  visitTypeIds: [],
  visitTypeName: '',
  deps: [], //科室
  depIds: [],
  depName: '',
  fees: [], //申请项目
  feeIds: [],
  feeName: '',
  applicants: [], //申请医师
  applicantIds: [],
  applicantName: '',
  registrants: [], //检验医师
  registrantIds: [],
  registrantName: '',
  reviewers: [], //审核医师
  reviewerIds: [],
  reviewerName: '',
  sampleNo: '',
  patTypes: [],
  reqDepts: [],
  itemNos: [],
  isChk: '',
  isUrgent: '',
  reqDoctor: '',
  reqDoctorName: '',
  testDoctor: '',
  testDoctorName: '',
  chkDoctor: '',
  chkDoctorName: ''
});
//public saveAs = require('file-saver');
let selectOpts = [
  {
    req: '1',
    field: 'year',
    name: '年'
  },
  {
    req: '2',
    field: 'month',
    name: '月'
  },
  {
    req: '3',
    field: 'day',
    name: '日'
  },
  {
    req: '4',
    field: 'rptGroupName',
    name: '报告单元'
  },
  {
    req: '5',
    field: 'testDoctor',
    name: '检验医生'
  },
  {
    req: '6',
    field: 'chkDoctor',
    name: '审核医生'
  },
  {
    req: '7',
    field: 'orgName',
    name: '组织机构'
  },
  {
    req: '8',
    field: 'patType',
    name: '病人类型'
  },
  {
    req: '9',
    field: 'reqDeptName',
    name: '科室'
  },
  {
    req: '10',
    field: 'sampleTypeName',
    name: '样本类型'
  },
  {
    req: '11',
    field: 'sex',
    name: '性别'
  },
  {
    req: '12',
    field: 'itemNa',
    name: '申请项目'
  },
  {
    req: '13',
    field: 'patCount',
    name: '病人数'
  },
  {
    req: '14',
    field: 'specCount',
    name: '标本数'
  },
  {
    req: '15',
    field: 'wlCount',
    name: '检验数'
  },
  {
    req: '16',
    field: 'count',
    name: '项目数'
  },
  {
    req: '17',
    field: 'amount',
    name: '金额'
  }
];

let checkArr = [selectOpts[12], selectOpts[13], selectOpts[14], selectOpts[15], selectOpts[16]];

const shortcuts = [
  {
    text: '今天',
    value: new Date()
  },
  {
    text: '昨天',
    value: () => {
      const date = new Date();
      date.setDate(date.getDate() - 1);
      return date;
    }
  },
  {
    text: '一周前',
    value: () => {
      const date = new Date();
      date.setDate(date.getDate() - 7);
      return date;
    }
  }
];

// 页面加载时字典
onMounted(() => {
  getDepyOptions(); //获取科室
  findOrganizationList(); //获取组织机构
  getDictPatTypeList(); //病人类型
  getDictChkStatusList(); //审核状态
  proxy.$nextTick(() => {
    const $table = proxy.$refs.selectOptTable;
    $table.setCheckboxRow(checkArr, true);
  });
});

function created() {
  wLColumns = [...wLColumnsFixed];
  rowDrop();
}
function mounted() {
  const $table = proxy.$refs.selectOptTable as any;
  this.selectOpts.forEach((item) => {
    $table.setCheckboxRow(item, item.isInclued);
  });
  // const $table = proxy.$refs.selectOptTable;
}

//获取审核状态数据字典
function getDictChkStatusList() {
  chkStatusList.length = 0;
  const url = '/api/sys/basDictDetail/findDictDetailList';
  proxy.$http
    .get(url, { params: { code: 'chkStatus' } })
    .then((res: any) => {
      chkStatusList.push(...res.data);
    })
    .catch((err: any) => {
      proxy.$alert(err, '提示');
    });
}

//获取病人类型
function getDictPatTypeList() {
  patTypeList.length = 0;
  const url = '/api/sys/basDictDetail/findDictDetailList';
  proxy.$http
    .get(url, { params: { code: 'PATTYPE' } })
    .then((res: any) => {
      patTypeList.push(...res.data);
    })
    .catch((err: any) => {
      proxy.$alert(err, '提示');
    });
}

/**
 * 选择医师
 */
function pullDownConfirm(e) {
  if (e) {
    e.aimKeys.forEach((item) => {
      form[item.targetField] = e.row[item.sourceField];
    });
  }
}

// 获取所有部门选项(下拉框)
function getDepyOptions() {
  const url = '/api/sys/findDepartmentList';
  proxy.$http
    .get(url, { params: { orgId: store.userInfo.orgId } })
    .then((res: any) => {
      deptOptions.push(...res.data.deptList);
    })
    .catch((err: any) => {
      VxeMessage('获取所有部门选项(下拉框)失败', VxeNotifyType.error);
    });
}

// 获取所有组织选项(下拉框)
function findOrganizationList() {
  OrganizationList.length = 0;
  const url = '/api/sys/findOrganizationList';
  proxy.$http
    .get(url, { params: { orgId: store.userInfo.orgId } })
    .then((res: any) => {
      OrganizationList.push(...res.data);
    })
    .catch((err: any) => {
      VxeMessage('获取所有组织选项(下拉框)失败', VxeNotifyType.error);
    });
}

// #region 【拖动排序】
let sortable = null;
let showHelpTip1 = false;
function beforeDestroy() {
  if (sortable) {
    sortable.destroy();
  }
}
function rowDrop() {
  proxy.$nextTick(() => {
    const xTable = proxy.$refs.selectOptTable as any;
    sortable = Sortable.create(xTable.$el.querySelector('.body--wrapper>.vxe-table--body tbody'), {
      handle: '.drag-btn',
      onEnd: ({ newIndex, oldIndex }) => {
        const currRow = selectOpts.splice(oldIndex, 1)[0];
        selectOpts.splice(newIndex, 0, currRow);
      }
    });
  });
}
// 查询
function handleSearch() {
  const $table = proxy.$refs.selectOptTable;
  let checkedList = $table.getCheckboxRecords();
  // console.log('checkedList', checkedList);

  tableHeaders = checkedList;

  getWklt();
}
//获取工作列表
function searchWklt(selectedRadioId, selectedName) {
  form.rptGroup = selectedRadioId.value;
  getWklt();
}

// 获取工作列表
function getWklt() {
  Wloading.value = true;
  tableHeaders.length = 0;
  tableList.length = 0;
  const dataObj = {};
  const arr = (proxy.$refs.selectOptTable as any).getCheckboxRecords(true);
  arr.forEach((item, index) => {
    dataObj[item.key] = {
      isInclued: true,
      fieldNo: index,
      displayType: 1,
      isColumn: true,
      isRow: true
    };
  });
  if (arr.length === 0) {
    proxy.$XModal.message({ content: '未勾选统计项目', status: 'error' });
    Wloading.value = false;
    return;
  }

  const url = '/lab/maininfo/reqQueryInfo';
  // 病人类型
  form.visitTypes.forEach((item) => {
    patTypeCodes.push(item.code);
  });

  //科室
  form.deps.forEach((item) => {
    reqDeptCodes.push(item.code);
  });
  //申请项目
  form.fees.forEach((item) => {
    itemNosCodes.push(item.feeCode);
  });

  //检验医师
  form.registrants.forEach((item) => {
    testDoctorCodes.push(item.username);
  });
  //审核医师
  form.reviewers.forEach((item) => {
    chkDoctorCodes.push(item.username);
  });
  const data = {
    sampledaBegin: form.sampledaBegin,
    sampledaEnd: form.sampledaEnd,
    orgIds: form.organizationUnitIds, //组织机构(id)
    campusAreas: form.campusAreas, //院区
    rptGroups: form.rptGroupIds, //报告单元(id)
    sampleNo: form.sampleNo,
    patTypes: patTypeCodes, //病人类型(code)
    reqDepts: reqDeptCodes, //科室(code)
    itemNos: itemNosCodes, //申请项目(feeCode √)
    isChk: form.isChk,
    isUrgent: form.isUrgent,
    reqDoctor: form.applicantIds, //申请医师(无勾选条件)
    testDoctor: testDoctorCodes, //检验医师(username)
    chkDoctor: chkDoctorCodes, //审核医师(username)
    queryFields: arr

    // 多选组件
    // organizationUnitIds:form.organizationUnitIds,//组织机构
    // rptGroupIds:form.rptGroupIds,//报告单元
    // visitTypeIds:form.visitTypeIds,//病人类型
    // depIds:form.depIds,//科室
    // feeIds:form.feeIds,//申请项目
    // applicantIds:form.applicantIds, //申请医师
    // registrantIds:form.registrantIds,//检验医师
    // reviewerIds:form.reviewerIds//审核医师
  };
  // data.groupOpts = arr;
  proxy.$http
    .post(url, data)
    .then((res: any) => {
      res.data.headers.forEach((item) => {
        item.field = item.field.slice(0, 1).toLowerCase() + item.field.slice(1);
      });
      tableHeaders.push(...res.data.headers);
      tableList.push(...res.data.data);

      Wloading.value = false;
    })
    .catch((err) => {
      Wloading.value = false;
      proxy.$alert(err.data.error.message, '提示');
    });
}

//左侧上下改变
function paneChange(e) {
  hTopSize = e[0].size;
}
//导出excel
function htmlToExcel(dom, title = '表格') {
  (proxy.$refs.wlAnsGeneralStatisticTable as any).exportData({ type: 'csv', filename: title, useStyle: true });
}
//选择改变
function checkBoxChange(item, e) {
  if (e) {
    const isHas =
      wLColumnsSelect.filter((op) => {
        op.key === item.key;
      }).length > 0;
    if (!isHas) {
      wLColumnsSelect.push({ key: item.key, name: item.name, align: 'left' });
    }
  } else {
    let isHas = false,
      i = -1;
    for (let index = 0; index < wLColumnsSelect.length; index++) {
      const element = wLColumnsSelect[index];
      if (element.key === item.key) {
        isHas = true;
        i = index;
        break;
      }
    }
    if (isHas) {
      wLColumnsSelect.splice(i, 1);
    }
  }
  wLColumns = [...wLColumnsSelect, ...wLColumnsFixed];
  proxy.$forceUpdate();
}

// 合计
function footerMethod({ columns, data }) {
  const rowData = [];
  columns.forEach((col, index) => {
    if (index === 0) {
      rowData.push('合计');
    } else if (col.params.isValue) {
      rowData.push(0);
      data.forEach((item) => {
        rowData[index] += IsEmpty(item[col.field]) ? 0 : item[col.field];
      });
    } else {
      rowData.push('');
    }
  });
  return [rowData];
}
// 点击组件表格行
function SelectRowClick(row) {
  form.reqDoctor = row.username;
  form.reqDoctorName = row.realname;
}
// 点击组件表格行
function SelectRowClick1(row) {
  form.testDoctor = row.username;
  form.testDoctorName = row.realname;
}
// 点击组件表格行
function SelectRowClick2(row) {
  form.chkDoctor = row.username;
  form.chkDoctorName = row.realname;
}
// 清空组件输入框
function clearValueHandler() {
  form.reqDoctor = '';
  form.reqDoctorName = '';
}
// 清空组件输入框
function clearValueHandler1() {
  form.testDoctor = '';
  form.testDoctorName = '';
}
// 清空组件输入框
function clearValueHandler2() {
  form.chkDoctor = '';
  form.chkDoctorName = '';
}

function confirmList(data, keyName) {
  form[keyName + 's'] = [];
  form[keyName + 'Ids'] = [];
  form[keyName + 'Name'] = '';
  if (IsEmpty(data.aimKeys) || data.aimKeys.length === 0) {
    const arr = data.arr;
    form[keyName + 's'] = arr;
    if (arr.length !== 0) {
      arr.forEach((item) => {
        if (item.id) {
          form[keyName + 'Ids'].push(item.id);
        } else {
          form[keyName + 'Ids'].push(item.code);
        }
        if (item.name) {
          form[keyName + 'Name'] += item.name + ',';
        } else if (item[keyName + 'Name']) {
          form[keyName + 'Name'] += item[keyName + 'Name'] + ',';
        } else {
          form[keyName + 'Name'] += item.realname + ',';
        }
      });

      if (form[keyName + 'Name'] && form[keyName + 'Name'].trim()) {
        form[keyName + 'Name'] = form[keyName + 'Name'].slice(0, -1);
      }
    }
  } else {
    data.arr.forEach((item) => {
      data.aimKeys.forEach((val) => {
        form[val.targetField + 's'].push(item);
        form[val.targetField + 'Ids'].push(item[val.targetField + 'Id']);
        form[val.targetField + 'Name'] += item[val.targetField].name + ',';
      });
    });
  }
}
function confirmCodeList(data, keyName) {
  form[keyName + 's'] = [];
  form[keyName + 'Ids'] = [];
  form[keyName + 'Name'] = '';
  if (IsEmpty(data.aimKeys) || data.aimKeys.length === 0) {
    const arr = data.arr;
    form[keyName + 's'] = arr;
    if (arr.length !== 0) {
      arr.forEach((item) => {
        form[keyName + 'Ids'].push(item.rptGroup);
        if (item.name) {
          form[keyName + 'Name'] += item.name + ',';
        } else if (item[keyName + 'Name']) {
          form[keyName + 'Name'] += item[keyName + 'Name'] + ',';
        } else {
          form[keyName + 'Name'] += item.realname + ',';
        }
      });

      if (form[keyName + 'Name'] && form[keyName + 'Name'].trim()) {
        form[keyName + 'Name'] = form[keyName + 'Name'].slice(0, -1);
      }
    }
  } else {
    data.arr.forEach((item) => {
      data.aimKeys.forEach((val) => {
        form[val.targetField + 's'].push(item);
        form[val.targetField + 'Ids'].push(item[val.targetField + 'Id']);
        form[val.targetField + 'Name'] += item[val.targetField].name + ',';
      });
    });
  }
}

let rptGroupRef = ref(null);

function confirmCampusAreaList(data) {
  form.campusAreas = [];
  form.campusAreaIds = [];
  form.campusAreaName = '';
  //清空报告单元
  form.rptGroups = [];
  form.rptGroupIds = [];
  form.rptGroupName = '';
  rptGroupRef.value?.clearConfirmEvent({});
  const arr = data.arr;
  if (arr.length !== 0) {
    arr.forEach((item) => {
      if (item.id) {
        form.campusAreaIds.push(item.id);
      }
      if (item.campusCode) {
        form.campusAreas.push(item.campusCode);
      }
      if (item.campusName) {
        form.campusAreaName += item.campusName + ',';
      }
    });
    if (form.campusAreaName && form.campusAreaName.trim()) {
      form.campusAreaName = form.campusAreaName.slice(0, -1);
    }
  }
}


</script>
<style lang="scss" scoped>
@page {
  size: auto;
  margin: 0mm;
}
@media print {
  :deep(.el-table__header) {
    table-layout: auto;
    width: 100% !important;
  }
  :deep(.el-table__body) {
    table-layout: auto;
    width: 100% !important;
  }

  .el-table__row {
    table-layout: auto;
    width: 100% !important;
  }

  .el-table--border th,
  .el-table--border td {
    border-right: 1px solid #ebeef5;
  }

  .el-table th,
  .el-table td {
    padding: 0px;
  }

  .el-table .cell {
    padding-right: 0px;
  }

  .el-table {
    width: 100% !important;
  }
}

.sortable-row-demo .drag-btn {
  cursor: move;
  font-size: 12px;
}

.sortable-row-demo .vxe-body--row.sortable-ghost,
.sortable-row-demo .vxe-body--row.sortable-chosen {
  background-color: #dfecfb;
}
.el-table__header {
  table-layout: auto;
}
.el-table__body {
  table-layout: auto !important;
}
.el-table--border th,
.el-table--border td {
  border-right: 1px solid #ebeef5;
}
.el-table th,
.el-table td {
  padding: 0px;
  word-wrap: normal !important;
  width: auto !important;
  word-break: break-all !important;
}
.el-table .cell {
  padding-right: 0px;
}

#Zhtjsqxm {
  height: 100%;
  .bodyContent {
    height: calc(100% - 60px);
    .tools {
      padding: 5px !important;
    }
    .bottomBox {
      height: calc(100% - 34px);
      .area {
        height: 100%;
        background-color: $base-white;
        :deep(.el-scrollbar__view) {
          height: 100%;
        }
      }
    }
  }

  :deep(.vxe-table) {
    .table-footer {
      font-weight: 700;
    }
  }
  .el-table.wLTable {
    th > .cell {
      padding: 0;
    }
    .cell.el-tooltip {
      min-width: 0;
      padding: 0 2px;
      // 急诊
      .el-icon-first-aid-kit {
        color: $danger-color;
      }
      // 打印
      .el-icon-printer {
        color: $warning-color;
      }
      // 审核
      .el-icon-coordinate {
        color: $brand-color;
      }
      // 完成
      .el-icon-circle-check {
        color: $success-color;
      }
      // 危急
      .el-icon-warning {
        color: $danger-color;
      }
    }
  }
}
</style>
